<?php
class WimageController extends OAuth2Controller {
    protected $app_type = 'image';
    public $layout = '/layouts/layui';  //布局文件
    /**
     * 图片列表
    */
    public function actionList() {
        if (empty($this->userId)) {
            $this->error('未授权，无法访问');
        }

        $user = User::model()->findByPk($this->userId);
        if ($user === null) {
            $this->error('微信用户不存在');
        }
        $pid = Yii::app()->request->getParam('pid');
        if (empty($pid)) {
            $this->error('参数非法');
        }
        if (Yii::app()->request->isAjaxRequest) {
            $params = array(
                'pid' => $pid,
                'page' => Yii::app()->request->getParam('page',1),
                'keyword' => Yii::app()->request->getParam('keyword',''),
            );
            $data_list = $user->wechatUserImg($params);
            $data = array(
                'code' => 0,
                'data' => $data_list
            );
            $this->jsonResponse($data);
        } else {
            $floder  = Floder::model()->findByPk($pid);
            $this->renderPartial('list', array('floder'=>$floder));
        }
    }

    /**
     * 获取图片详情
    */
    public function actionDetail() {
        $id = Yii::app()->request->getParam('id');
        if (empty($id)) {
            $this->error('参数非法');
        }
        $image = Image::model()->findByPk($id);
        if ($image === null) {
            $this->error('图片不存在');
        }
        $user_img_list = $image->userImgList($this->userId);
        if ($user_img_list === false) {
            $this->error($image->getErrors());
        }
        $params = array(
            'image' => $image,
            'img_list' => $user_img_list
        );
        $this->renderPartial('detail', $params);
    }
}